package com.fingard.dsp.bank.directbank.zjdsf01.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class StrSubstring {
	public static List<String> getStrList(String inputString, int length) throws IOException {
		int sourceLen = inputString.getBytes("GBK").length;
		int size = sourceLen / length;
		if (inputString.getBytes("GBK").length % length != 0) {
			size += 1;
		}
		return getStrList(inputString, length, size);
	}
	
	public static List<String> getStrList(String inputString, int length, int size) throws IOException {
		List<String> list = new ArrayList<String>();
		for (int index=0; index<size; index++) {
			String childStr = subString(inputString, index*length, (index+1)*length);
			list.add(childStr);
		}
		return list;
	}
	
	public static String subString(String str, int f, int t) throws IOException {
		 if (f > str.getBytes("GBK").length)
			 return null;
		 if (t > str.getBytes("GBK").length) {
			 return new String(str.getBytes("GBK"),f, str.getBytes("GBK").length, "GBK");
		 } else {
			 return new String(str.getBytes("GBK"),f,t-f, "GBK");
		 }
	}
}